//
//  OnSaleViewModel.m
//  GLGW_Shoping
//
//  Created by whx on 2018/12/10.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "OnSaleViewModel.h"
#import "OnSaleTableViewCell.h"
#import "NoDataFootTableViewHeaderFooterView.h"
#import "OnSaleHeaderView.h"
#import "OnSaleFooterView.h"
#import "OrderOperationView.h"
#import "GoodsInforSysView.h"

@interface OnSaleViewModel ()<UITableViewDelegate, UITableViewDataSource>
{
    UITableView *selfTableView;
}

@end

@implementation OnSaleViewModel

- (instancetype)initWithViewToViewModel:(UITableView *)tableView theSuperView:(UIView *)superView
{
    if (self = [super initWithViewToViewModel:tableView theSuperView:superView]) {
        
        tableView.height -= kHeightProportion_In_iPhoneTriploid(44);
        tableView.delegate = self;
        tableView.dataSource = self;
        [tableView registerClass:[OnSaleHeaderView class] forHeaderFooterViewReuseIdentifier:@"OnSaleHeaderView"];
        [tableView registerClass:[OnSaleFooterView class] forHeaderFooterViewReuseIdentifier:@"OnSaleFooterView"];
        [superView addSubview:tableView];
    }
    return self;
}

- (void)setType:(OnSaleType)type
{
    _type = type;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return kHeightProportion_In_iPhoneTriploid(65);
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return kHeightProportion_In_iPhoneTriploid(50);
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return kHeightProportion_In_iPhoneTriploid(121);
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    OnSaleHeaderView *header = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"OnSaleHeaderView"];
    return header;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    OnSaleFooterView *footer = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"OnSaleFooterView"];
    kWeakSelf(self);
    footer.Block_BottomAction = ^(GLGWButton * _Nullable but) {
        [weakself seleBttom:but];
    };
    return footer;
}

#pragma mark - tableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 4;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    OnSaleTableViewCell *cell = [OnSaleTableViewCell cellWithTableView:tableView];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.BlockSelecRow) {
        self.BlockSelecRow(indexPath);
    }
}

- (void)seleBttom:(GLGWButton *)sender
{
    if (sender.tag == 234) { // 上架 下架
        OrderOperationView * opeartionView = [[OrderOperationView alloc] initWithPopOrderOperation:@[@"取消",@"确认上架"] theTitleStr:@"操作提示" theTosStr:@"您是否确认上架该商品？"];
        [opeartionView show];
        opeartionView.Block_CaseAction = ^(NSInteger tag) {
            if (tag == 311) {
            }
        };
    } else if (sender.tag == 235) { // 修改价格
        GoodsInforSysView * syncGoodsInforView = [[GoodsInforSysView alloc] initWithGoodsInformationSync];
        syncGoodsInforView.Block_SysncAction = ^{
            
        };
    }
}

@end
